﻿@page "/register"
@inject NavigationManager Nav
@inject MessageService Message
@layout EmptyLayout
@using lcwb.Shared.Model.User
<Card Title="LCWB用户注册" Bordered="true" Class="register-card">
    <Form Model="@registerModel" OnFinish="HandleRegistration">
        <DataAnnotationsValidator />
        <FormItem Label="名称" Required="true">
            <InputText @bind-Value="registerModel.Name"/>
            <ValidationMessage For="() => registerModel.Name" />
        </FormItem>

        <FormItem Label="邮箱" Required="true">
            <InputText @bind-Value="registerModel.Email" />
            <ValidationMessage For="() => registerModel.Email" />
        </FormItem>
        <FormItem Label="密码" Required="true">
            <InputText @bind-Value="registerModel.Password" />
            <ValidationMessage For="() => registerModel.Password" />
        </FormItem>

        <FormItem Label="手机号">
            <InputText @bind-Value="registerModel.PhoneNumber"/>
            <ValidationMessage For="() => registerModel.PhoneNumber" />
        </FormItem>

        <FormItem Label="地址栏">
            <InputTextArea @bind-Value="registerModel.Address" />
            <ValidationMessage For="() => registerModel.Address" />
        </FormItem>
        <div class="button-container">
            <Button Type="ButtonType.Primary" HtmlType="submit" Loading="@isSubmitting">
                立即注册
            </Button>
        </div>
    </Form>
</Card>

<style>
    .register-card {
        width: 400px;
        margin: 80px auto;
        border-radius: 12px;
        box-shadow: 0 4px 24px rgba(0,0,0,0.12);
        background: #ffffff;
    }
    .button-container {
        display: flex;
        justify-content: center;
        margin-top: 24px;
    }

    .ant-form-item {
        margin-bottom: 20px;
    }

    .ant-form-item-label > label {
        font-size: 14px;
        color: #333333;
        line-height: 22px;
        padding-right: 12px;
    }

    .ant-input {
        border: 1px solid #e0e0e0;
        border-radius: 6px;
        height: 44px;
        font-size: 14px;
        transition: all 0.2s;
    }

</style>

@code {
    private UserRegisterModel registerModel = new();
    private bool isSubmitting = false;


    private async Task HandleRegistration()
    {
        isSubmitting = true;
        // 模拟API调用
        await Task.Delay(1000);
        // 实际开发中应替换为真实API调用
        isSubmitting = false;

        await Message.Success("注册成功");
        Nav.NavigateTo("/login");
    }

}